//
//  MoreDetailCell.m
//  shise
//
//  Created by 徐国庆 on 14/12/17.
//  Copyright (c) 2014年 apple. All rights reserved.
//

#import "MoreDetailCell.h"
#import "UIImageView+WebCache.h"
@implementation MoreDetailCell

- (void)awakeFromNib {
    // Initialization code
}

// 属性初始化
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        
        
//        self.contentView.backgroundColor = [UIColor blackColor];
        self.foodImageView = [[UIImageView alloc] init];
//        self.foodImageView.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.foodImageView];
        [self.foodImageView release];
        
        self.foodImageViewButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [self.contentView addSubview:self.foodImageViewButton];
        
        self.imageVeiw = [[UIImageView alloc] init];
        self.imageVeiw.backgroundColor = [UIColor whiteColor];
        self.imageVeiw.layer.masksToBounds = YES;
        self.imageVeiw.layer.cornerRadius = 16;
        [self.contentView addSubview:self.imageVeiw];
        [self.imageVeiw release];
        
        self.userHeadImageView = [[UIImageView alloc] init];
//        self.userHeadImageView.backgroundColor = [UIColor greenColor];
        self.userHeadImageView.layer.masksToBounds = YES;
        self.userHeadImageView.layer.cornerRadius = 16;
        [self.contentView addSubview:self.userHeadImageView];
        [self.userHeadImageView release];
        
        self.foodDoyenImageView = [[UIImageView alloc] init];
//        self.foodDoyenImageView.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.foodDoyenImageView];
        [self.foodDoyenImageView release];
        
        self.userHeadImageViewButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [self.contentView addSubview:self.userHeadImageViewButton];
        
        self.userName = [[UILabel alloc] init];
//        self.userName.backgroundColor = [UIColor blueColor];
        self.userName.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.userName];
        [self.userName release];
        
        self.gradeImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.gradeImageView];
        [self.gradeImageView release];
        
        self.userAddress = [[UILabel alloc] init];
//        self.userAddress.backgroundColor = [UIColor redColor];
        self.userAddress.font = [UIFont systemFontOfSize:13];
        self.userAddress.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:self.userAddress];
        [self.userAddress release];
        
        self.userSay = [[UILabel alloc] init];
//        self.userSay.backgroundColor = [UIColor brownColor];
//        self.userSay.numberOfLines = 2;
        [self.contentView addSubview:self.userSay];
        [self.userSay release];
        
        self.praiseImageView = [[UIImageView alloc] init];
//        self.praiseImageView.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:self.praiseImageView];
        [self.praiseImageView release];
        
        self.praiseImageViewButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [self.praiseImageViewButton setTitle:nil forState:UIControlStateNormal];
        [self.contentView addSubview:self.praiseImageViewButton];
        
        self.praise = [[UILabel alloc] init];
//        self.praise.backgroundColor = [UIColor blueColor];
        self.praise.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.praise];
        [self.praise release];
        
        self.praiseNumbers = [[UILabel alloc] init];
//        self.praiseNumbers.backgroundColor = [UIColor redColor];
        self.praiseNumbers.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.praiseNumbers];
        [self.praiseNumbers release];
        
        self.markImageView = [[UIImageView alloc] init];
//        self.markImageView.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:self.markImageView];
        [self.markImageView release];
        
        self.markImagViewButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [self.contentView addSubview:self.markImagViewButton];
        
        self.mark = [[UILabel alloc] init];
//        self.mark.backgroundColor = [UIColor blueColor];
        self.mark.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.mark];
        [self.mark release];
        
        self.markNumber = [[UILabel alloc] init];
//        self.markNumber.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.markNumber];
        [self.markNumber release];
        
        self.middleLabel = [[UILabel alloc] init];
        self.middleLabel.text = @"|";
        self.middleLabel.textAlignment = NSTextAlignmentCenter;
        self.middleLabel.alpha = 0.2;
        [self.contentView addSubview:self.middleLabel];
        [self.middleLabel release];
        
//        self.alpha = 0;
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.foodImageView.frame = CGRectMake(5, 5, self.contentView.frame.size.width - 10, 300);
    self.imageVeiw.frame = CGRectMake(13, 293, 34, 33);
    self.userHeadImageView.frame = CGRectMake(15, 295, 30, 30);
    self.userAddress.frame = CGRectMake(240, 310, 120, 20);
    self.userSay.frame = CGRectMake(20, 340, self.contentView.frame.size.width - 40, 20);
    self.foodImageView.frame = CGRectMake(5, 5, self.contentView.frame.size.width - 10, 300);
    self.userHeadImageView.frame = CGRectMake(15, 295, 30, 30);
    self.userName.frame = CGRectMake(47, 310, 100, 20);
    self.userAddress.frame = CGRectMake(self.contentView.frame.size.width - 180, 310, 150, 20);
    self.userSay.frame = CGRectMake(10, 340, self.contentView.frame.size.width - 20, 0);
    self.userSay.alpha = 0.4;
//    self.userSay.numberOfLines = 0;
//    NSLog(@"宽%f， 高%f", self.foodImageView.frame.size.width, self.foodImageView.frame.size.height);
    self.praiseImageView.frame = CGRectMake(40, self.contentView.frame.size.height - 27, 20, 20);
    self.praise.frame = CGRectMake(75, self.contentView.frame.size.height - 27, 40, 20);
    self.praiseNumbers.frame = CGRectMake(110, self.contentView.frame.size.height - 27, 40, 20);
    self.markImageView.frame = CGRectMake(220, self.contentView.frame.size.height - 27, 20, 20);
    self.mark.frame = CGRectMake(255, self.contentView.frame.size.height - 27, 60, 20);
    self.markNumber.frame = CGRectMake(280, self.contentView.frame.size.height - 27, 20, 20);
    
    self.foodImageViewButton.frame = CGRectMake(5, 5, 365, 300);
    self.userHeadImageViewButton.frame = CGRectMake(15, 293, 30, 40);
    self.praiseImageViewButton.frame = CGRectMake(40, self.contentView.frame.size.height - 20, 140, 20);
    self.markImagViewButton.frame = CGRectMake(220, self.contentView.frame.size.height - 22, 80, 25);
    
    self.middleLabel.frame = CGRectMake(self.contentView.frame.size.width / 2 - 10, self.mark.frame.origin.y, 10, 20);
    
    [self.userSay sizeToFit];
}

// mzp 写的  重写setter方法 用对象给cell 赋值
- (void)setFood:(Food *)food
{
    if (_food != food) {
        [_food release];
        _food = [food retain];
    }
    
    [_foodImageView setImageWithURL:[NSURL URLWithString:_food.pic_url] placeholderImage:[UIImage imageNamed:@"wait.jpg"]];
    
    
//    [_foodImageView setImageWithURL:[NSURL URLWithString:_food.pic_url]];
    
    NSDictionary *userDic = [NSDictionary dictionaryWithDictionary:_food.user];
    [_userHeadImageView setImageWithURL:[NSURL URLWithString:[userDic objectForKey:@"avatar"]] placeholderImage:[UIImage imageNamed:@"tou.jpg"]];
    
    _userName.text = _food.userName;
    _userAddress.text = _food.location;
    
    _praiseNumbers.text = [NSString stringWithFormat:@"%@", _food.likeCount];
    
    _userSay.text = _food.content;
    _userSay.numberOfLines = 2;
    _userSay.font = [UIFont boldSystemFontOfSize:15];
    
    _praiseImageView.image = [UIImage imageNamed:@"praiseFont.png"];
    _praise.text = @"赞";
    
    _markImageView.image = [UIImage imageNamed:@"mark.png"];
    _mark.text = @"收藏";
}



- (void)dealloc
{
//    @property(nonatomic, retain)UIImageView *foodImageView;// 美食照片
//    @property(nonatomic, retain)UIImageView *userHeadImageView;// 用户头像照片
//    @property(nonatomic, retain)UILabel *userName;// 用户名
//    @property(nonatomic, retain)UILabel *userAddress;// 用户地址
//    @property(nonatomic, retain)UILabel *userSay;// 用户说得话
//    @property(nonatomic, retain)UIImageView *praiseImageView;// 代表赞的图片
//    @property(nonatomic, retain)UILabel *praise;// ”赞“
//    @property(nonatomic, retain)UILabel *praiseNumbers;// 赞的人数
//    @property(nonatomic, retain)UIImageView *markImageView;// 代表马克的图片
//    @property(nonatomic, retain)UILabel *mark;// “马克”
//    @property(nonatomic, retain)UILabel *markNumber;// 马克的人数
//    @property(nonatomic, retain)UIImageView *imageVeiw; // 设置头像图片下面的白色图边框图片
//    @property(nonatomic, retain)UIImageView *gradeImageView;// 设置等级图片
//    @property(nonatomic, retain)UIImageView *foodDoyenImageView;// 设置食色达人图片
//    
//    @property(nonatomic, retain)UIButton *foodImageViewButton;// 美食图片上附加的按钮
//    @property(nonatomic, retain)UIButton *userHeadImageViewButton;// 用户头像上附加的按钮
//    @property(nonatomic, retain)UIButton *praiseImageViewButton;// “赞”上附加的按钮
//    @property(nonatomic, retain)UIButton *markImagViewButton;// "马克"上附加的按钮
//    @property(nonatomic, retain)UILabel *middleLabel;
    

    
    [_foodImageView release];
    [_userHeadImageView release];
    [_userName release];
    [_userAddress release];
    [_userSay release];
    [_praiseImageView release];
    [_praise release];
    [_praiseNumbers release];
    [_markImageView release];
    [_mark release];
    [_markNumber release];
    [_imageVeiw release];
    [_gradeImageView release];
    [_foodDoyenImageView release];
    [_foodImageViewButton release];
    [_userHeadImageViewButton release];
    [_praiseImageViewButton release];
    [_markImagViewButton release];
    [_middleLabel release];
    [super dealloc];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.imageVeiw.backgroundColor = [UIColor whiteColor];
    // Configure the view for the selected state
}

@end
